#!/bin/bash

#
# This script manipulates the sample clock divider gpio pins for Prj123
#

echo "Configuring Prj123 sample clock divider"
S0=0; 
S1=0; 
if [ "$1" = "1" ]; then
    S0=1; 
    S1=0; 
fi
if [ "$1" = "2" ]; then
    S0=0; 
    S1=1; 
fi
if [ "$1" = "3" ]; then
    S0=1; 
    S1=1; 
fi
echo "S1 S0 = " $S1 $S0


# 32*bbb_gpioN+bbb_gpioN_bitM

# S1 = bbb_gpio3_15 = gpio111
if [ ! -d /sys/class/gpio/gpio111 ]; then  echo 111 > /sys/class/gpio/export; fi
echo  out > /sys/class/gpio/gpio111/direction
echo  $S1 > /sys/class/gpio/gpio111/value

# S0 = bbb_gpio3_17 = gpio113
if [ ! -d /sys/class/gpio/gpio113 ]; then  echo 113 > /sys/class/gpio/export; fi
echo  out > /sys/class/gpio/gpio113/direction
echo  $S0 > /sys/class/gpio/gpio113/value

# Show final values
echo "S0 "
cat   /sys/class/gpio/gpio113/value
echo "S1 "
cat   /sys/class/gpio/gpio111/value
